import { Component, OnInit } from '@angular/core';


@Component({
  selector: 'app-input-tree',
  templateUrl: './input-tree.component.html',
  styleUrls: ['./input-tree.component.scss'],
})
export class InputTreeComponent implements OnInit {

  someList: string[] | undefined;
  elList = ["person", "{", "type:1", "age:2", "name:3", "}"]
  str = `
      person {
        type:1
        age:2
        name:3

      }`;

  constructor() {}

  ngOnInit(): void {
    this.someList = this.spliceList()
    console.log('someList',this.someList);

  }

  spliceList() {
    let code = this.str.split(/[(\r\n\s)\r\n\s]+/); // 根据换行或者回车进行识别
    code.forEach((item, index) => {
      // 删除空项
      if (!item) {
        code.splice(index, 1);
      }
    });
    code = Array.from(new Set(code)); // 去重

    let code2 = this.elList.join("\n")


    return code;
  }

}
